package com.example.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mapper.UserMapper;
import com.example.model.UserDO;
import com.example.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public String login(String username, String password) {
        UserDO userDO = userMapper.selectOne(new QueryWrapper<UserDO>().eq("name", username));

        if (userDO == null) {
            return "登錄失敗";
        }

        if (username.equals(userDO.getName()) && password.equals(userDO.getPassword())) {
            StpUtil.login(userDO.getId());
            return "登錄成功";
        } else {
            return "登錄失敗";
        }
    }
}
